package com.sun.hunk.struts.action;

import com.sun.hunk.hibernate.dao.InvoiceDAO;
import com.sun.hunk.hibernate.domain.Invoice;
import com.sun.hunk.struts.HunkDispatchAction;
import com.sun.hunk.struts.form.SearchForm;
import com.sun.hunk.util.CommonUtil;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author sunil
 */
public class SearchAction extends HunkDispatchAction {

    public ActionForward searchInvoice(ActionMapping mapping, ActionForm f, HttpServletRequest request, HttpServletResponse response) throws Exception {
        SearchForm form = (SearchForm) f;
          Map<String, Object> map = new HashMap<String, Object>();
        if (CommonUtil.isNotEmpty(form.getInvoiceNo())) {
            map.put("invoiceNo", form.getInvoiceNo());
        }
        if (CommonUtil.isNotEmpty(form.getOrderNo())) {
            map.put("orderNo", form.getOrderNo());
        }
        if (CommonUtil.isNotEmpty(form.getVesselNo())) {
            map.put("vesselNo", form.getVesselNo());
        }
        if (CommonUtil.isNotEmpty(form.getPod())) {
            map.put("pod", form.getPod());
        }
        if (CommonUtil.isNotEmpty(form.getPol())) {
            map.put("pol", form.getPol());
        }
        if (CommonUtil.isNotEmpty(form.getDestination())) {
            map.put("destination", form.getDestination());
        }
        List<Invoice> list = new InvoiceDAO().find(map);        
        request.setAttribute("invoices", list);
        return mapping.findForward("invoice_search");
    }

}
